﻿using System;
using System.Windows.Forms;

namespace sy1_4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // 加法运算
        private void btnAdd_Click(object sender, EventArgs e)
        {
            double num1 = Convert.ToDouble(txtNum1.Text);
            double num2 = Convert.ToDouble(txtNum2.Text);
            txtResult.Text = (num1 + num2).ToString();
        }

        // 减法运算
        private void btnSubtract_Click(object sender, EventArgs e)
        {
            double num1 = Convert.ToDouble(txtNum1.Text);
            double num2 = Convert.ToDouble(txtNum2.Text);
            txtResult.Text = (num1 - num2).ToString();
        }

        // 乘法运算
        private void btnMultiply_Click(object sender, EventArgs e)
        {
            double num1 = Convert.ToDouble(txtNum1.Text);
            double num2 = Convert.ToDouble(txtNum2.Text);
            txtResult.Text = (num1 * num2).ToString();
        }

        // 除法运算
        private void btnDivide_Click(object sender, EventArgs e)
        {
            double num1 = Convert.ToDouble(txtNum1.Text);
            double num2 = Convert.ToDouble(txtNum2.Text);

            if (num2 == 0)
                txtResult.Text = "除数不能为0";
            else
                txtResult.Text = (num1 / num2).ToString();
        }

        // 清空文本框
        private void btnClear_Click(object sender, EventArgs e)
        {
            txtNum1.Clear();
            txtNum2.Clear();
            txtResult.Clear();
        }

        // 退出程序
        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
